home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / GCOOPE10.H < prev    next >
Text File  |  1994-07-23  |  5KB  |  220 lines

  1. /*
  2.  
  3.  
  4.     GCOOPE version 1.0 external header file
  5.  
  6.         by Brian Lee Price
  7.  
  8.     Released as Public Domain  July, 1994.
  9.  
  10. */
  11.  
  12. #ifndef _INTERNAL_
  13. #define _EXTERNAL_
  14. #endif
  15.  
  16. #include "gcstruct.h"
  17.  
  18. /* the following should always be used for method definition headers */
  19.  
  20. #define cmethod static
  21. #define imethod static
  22.  
  23. #ifdef __STRONG_TYPING__
  24.  
  25.   #include "typing.h"
  26.  
  27.   /*
  28.     Note: if strong typing is desired you should have a header file
  29.     named generics.h with the proto-typedefs in it, it will be
  30.     automatically included here when __STRONG_TYPING__ is defined.
  31.  
  32.     See "typing.h" for more info.
  33.   */
  34.  
  35.   #include "generics.h"
  36.  
  37. #endif
  38.  
  39.  
  40. /*
  41.  
  42.     NOTE: where the name of a generic function is:
  43.            symbolName
  44.  
  45.         If you are using strong typing;
  46.  
  47.         The variable referred to for generic functions
  48.         is GFsymbolName and the proto-typedef is symbolName.
  49.         See typing.h for further information.
  50.  
  51.  
  52.     You are free, of course, to adopt your own standards in
  53.     this regard.  Doing so will prevent use of most macros
  54.     defined here.
  55.  
  56. */
  57.  
  58.  
  59. /*
  60.     macro to name and declare installation routine.
  61.  
  62.     NOTE: the installation routine should return an stat value
  63.  
  64.     FUNCOKAY or FUNCFAIL.
  65.  
  66. */
  67.  
  68. #define CONCAT(parm1,parm2) parm1##parm2
  69.  
  70. #define CLASS_INSTALL stat CONCAT(CLASS,_Install)(void)
  71.  
  72. #define INSTALL_CLASS(className) if(className##_Install()) goto err;
  73.  
  74.  
  75. #ifdef __STRONG_TYPING__
  76.  
  77.   #define USEGEN(genFunc) extern generic GF##genFunc
  78.   #define MAKEGEN(genFunc) generic GF##genFunc
  79.   #define GEN(genFunc) GF##genFunc
  80.   #define INSTGEN(genFunc) \
  81.       if(MAX_GEN==(GF##genFunc=addGeneric((method) 0L))) goto err;
  82.  
  83. #else
  84.  
  85.   #define USEGEN(genFunc) extern generic genFunc
  86.   #define MAKEGEN(genFunc) generic genFunc
  87.   #define GEN(genFunc) genFunc
  88.   #define INSTGEN(genFunc) \
  89.       if(MAX_GEN==(genFunc=addGeneric((method) 0L))) goto err;
  90.  
  91. #endif
  92.  
  93. /* the following typedefs should be used when returning a float/double/ld */
  94.  
  95. typedef float (*floatMethod)(object,...);
  96. typedef floatMethod (*floatRetVal)(generic);
  97.  
  98. #define FLTRV floatRetVal
  99.  
  100. typedef double (*doubleMethod)(object,...);
  101. typedef doubleMethod (*doubleRetVal)(generic);
  102.  
  103. #define DBLRV doubleRetVal
  104.  
  105. typedef long double (*longDblMethod)(object,...);
  106. typedef longDblMethod (*longDblRetVal)(generic);
  107.  
  108. #define LDBLRV longDblRetVal
  109.  
  110. /*
  111.  
  112.     example:
  113.  
  114.     float x;
  115.     ....
  116.     x=((floatRetVal) g)(valueOf)(floatObject);
  117.  
  118.     This allows the compiler to correctly deal with floating point,
  119.     double precision, and long double type return values.
  120.  
  121.  
  122.     NOTE: these are designed for use seperately from the strong typing
  123.     option.  Although if you use the GEN macro you should be okay.
  124.  
  125. */
  126.  
  127.  
  128. /* in the same vein here are typedefs for common return types */
  129.  
  130. typedef char (*charMethod)(object,...);
  131. typedef charMethod (*charRetVal)(generic);
  132.  
  133. #define CHRRV charRetVal
  134.  
  135. typedef byte (*byteMethod)(object,...);
  136. typedef byteMethod (*byteRetVal)(generic);
  137.  
  138. #define BYTRV byteRetVal
  139.  
  140. typedef int (*intMethod)(object,...);
  141. typedef intMethod (*intRetVal)(generic);
  142.  
  143. #define INTRV intRetVal
  144.  
  145. typedef short (*shortMethod)(object,...);
  146. typedef shortMethod (*shortRetVal)(generic);
  147.  
  148. #define SHRTRV shortRetVal
  149.  
  150. typedef long (*longMethod)(object,...);
  151. typedef longMethod (*longRetVal)(generic);
  152.  
  153. #define LNGRV longRetVal
  154.  
  155. typedef void * (*voidPtrMethod)(object,...);
  156. typedef voidPtrMethod (*voidPtrRetVal)(generic);
  157.  
  158. #define VDPTRRV voidPtrRetVal
  159.  
  160. typedef unsigned short (*unsignedMethod)(object,...);
  161. typedef unsignedMethod (*unsignedRetVal)(generic);
  162.  
  163. #define UNSGNDRV unsignedRetVal
  164. #define WRDRV unsignedRetVal
  165.  
  166.  
  167. /*
  168. NOTE: normally you can safely use type object to return status info,
  169.     ie. FUNCFAIL / FUNCOKAY.
  170.  
  171. */
  172.  
  173.  
  174. /*
  175.     the following macros will assist method declarations as long as you
  176.     use the name m4genFunc for a generic named genFunc.  (Also, when
  177.     using the following do not preface genFunc with GF).
  178. */
  179.  
  180.  
  181. #define ADDGM(genFunc) \
  182. addGMthd(CLASS,GEN(genFunc),(method) CONCAT(m4,genFunc))
  183.  
  184. #define RMVGM(genFunc) \
  185. rmvGMthd(CLASS,GEN(genFunc))
  186.  
  187. #define RENGM(oldGenFunc,oldClass,newGenFunc) \
  188. cpyGMas(CLASS,GEN(newGenFunc),oldClass, GEN(oldGenFunc))
  189.  
  190. /*
  191.     as long as you always give the first parameter in a method the name
  192.     instance, instead of steer(ClassName, instance) you can use:
  193. */
  194.  
  195. #define ST(className) steer(className, instance)
  196.  
  197.  
  198. /*
  199.     some assistance macros for instance and class variable access.
  200.  
  201. */
  202.  
  203. #define IVPTR ((instVar *) getIVptr(instance))
  204.  
  205. #define DECLAREIV instVars * ivptr
  206.  
  207. #define GETIVPTR(errRet) if(NULL==(ivptr=getIVptr(instance))) return errRet
  208.  
  209. #define DECLARECV classVars * cvptr
  210.  
  211. #define CVPTR ((classVars *) getCVptr(CLASS))
  212.  
  213. #define GETCVPTR(errRet) if(NULL==(cvptr=getCVptr(CLASS))) return errRet
  214.  
  215.  
  216. /* finally, include the gcinit.h header file if not a class definition */
  217.  
  218. #ifndef CLASS
  219. #include "gcinit.h"
  220. #endif